%%
%作业1
%1
A = [1 2;3 4];
a = trace(A)
[b,c] = eig(A)
poly(A)
%%
%2
A = [2 1 1;1 2 1;1 1 2];
[a,b] = eig(A);
P = orth(a)
B = P'*A*P
P*P'
%%
%3
l1 = [1 2 1];
l2 = [1 -2 -1];
A = [2 -1 0;0 1 -2;2 1 0;0 -1 2];
b = [0;-4;7;3];
B = [A,b];
rank(A);
rank(B);
%异面直线
a2 = [1 2 3];
b2 = [3 1 2];
%计算方向向量的叉积
aa = [2 1;-2 -1];bb = [1 -1;1 1];cc = [1 2;1 -2];
aa1 = det(aa);bb1 = det(bb);cc1 = det(cc);
n = [aa1,bb1,cc1];
ff = n.*(a2-b2);
d = abs(sum(ff))/norm(n);
%%
%4
A = 1;B = 1;C = 1;D=1;
x0=1;y0=2;z0=3;
d = abs(A*x0+B*y0+C*z0+D)/sqrt(A.^2+B.^2+C.^2)
%%
%5
x = [1 2 3 4 1];
y = [3 1 2 4 3];

% 计算面积
A = polyarea(x, y);







